package com.xiaobo.client;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;

import com.xiaobo.util.HttpUtil;

public class NsrInfoActivity extends Activity {
	private String nsrnbm;//内部码
	private TextView nsrbm;//编码
	private TextView nsrmc;//名称
	private TextView djzt;//状态
	private TextView gljg;//管理机关
	private TextView zgy;//专管员
	private TextView sbfs;//申报方式
	private TextView zsfs;//征收方式
	private TextView djlx;//登记类型
	private TextView zclx;//注册类型
	private TextView hy;//行业
	private TextView xzjd;//县镇街道
	private String userKey;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.nsr_info);
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		nsrnbm = bundle.getString("nsrnbm");
		userKey=bundle.getString("userKey");
		//获得控件实例
		nsrbm = (TextView)findViewById(R.id.info_nsrbm);
		nsrmc = (TextView)findViewById(R.id.info_nsrmc);
		djzt = (TextView)findViewById(R.id.info_djzt);
		gljg = (TextView)findViewById(R.id.info_gljg);
		zgy = (TextView)findViewById(R.id.info_zgy);
		sbfs = (TextView)findViewById(R.id.info_sbfs);
		zsfs = (TextView)findViewById(R.id.info_zsfs);
		djlx = (TextView)findViewById(R.id.info_djlx);
		zclx = (TextView)findViewById(R.id.info_zclx);
		hy = (TextView)findViewById(R.id.info_hy);
		xzjd = (TextView)findViewById(R.id.info_xzjd);
		String result = getNsrBasicInfo(nsrnbm);
		if(result!=null&&!result.equals("net_error")){
			try {
				JSONObject obj = new JSONObject(result);
				nsrbm.setText(obj.getString("nsrbm"));
				nsrmc.setText(obj.getString("nsrmc"));
				djzt.setText(obj.getString("djzt"));
				gljg.setText(obj.getString("gljg"));
				zgy.setText(obj.getString("zgy"));
				sbfs.setText(obj.getString("sbfs"));
				zsfs.setText(obj.getString("zsfs"));
				djlx.setText(obj.getString("djlx"));
				zclx.setText(obj.getString("zclx"));
				hy.setText(obj.getString("hy"));
				xzjd.setText(obj.getString("xzjd"));
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}else{
			Toast toast = Toast.makeText(NsrInfoActivity.this, "网络异常!", Toast.LENGTH_LONG);
			toast.show();			
		}
		
	}
	public String getNsrBasicInfo(String nsrnbm){
		String url = HttpUtil.getNsrBasicInfo;//请求URL
		HttpPost req = HttpUtil.getHttpPost(url);//获得post请求对象
		String result = null;
		//请求参数
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("nsrnbm",nsrnbm));
		params.add(new BasicNameValuePair("userKey",userKey));

		try {
			//设置请求字符集 
			req.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
			//返回结果
			result = HttpUtil.getStringByPost(req);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		Intent intent = new Intent(NsrInfoActivity.this,ExitSystemActivity.class);
		startActivity(intent);
		return false;
	}
	
}
